﻿<cfsilent>
	<cfscript>
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		
		event.setArg("pageTitle", "教学运行基础数据 - 教学计划");
		
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		rs_plan = queryNew("institute_id, institute_short, prop_id1, prop_id2");
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		if ( len(academicYear) and len(academicTerm) ) {
			
			sql = "SELECT 
						c.institute_id, c.institute_short, 
						sum(case when d.prop_id='1' then 1 else 0 end) prop_id1,
						sum(case when d.prop_id='2' then 1 else 0 end) prop_id2 
					FROM t_schema a
						INNER JOIN t_course b ON b.cid = a.cid 
						INNER JOIN t_institute c ON c.institute_id = b.institute_id 
						INNER JOIN t_course_prop d ON d.prop_id = a.prop_id 
					WHERE 
						a.academic_year = :academicYear 
						AND 
						a.academic_term = :academicTerm 
					GROUP BY 
						c.institute_id, c.institute_short
					ORDER BY 
						c.institute_short ";
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="academicYear", value=academicYear, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="academicTerm", value=academicTerm, cfsqltype="cf_sql_char" );
			
			rs_plan = queryObj.execute( sql=sql ).getResult();
			
			sql = "SELECT 
						c.institute_id, c.institute_name 
					FROM t_schema a 
						INNER JOIN t_subject b ON b.sbj_id = a.sbj_id 
						INNER JOIN t_institute c ON c.institute_id = b.institute_id  
					WHERE 
						a.academic_year = :academicYear 
						AND
						a.academic_term = :academicTerm  
						AND 
						c.institute_id = :depId 
					GROUP BY 
						c.institute_id, c.institute_name
					ORDER BY 
						c.institute_name ASC";
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="academicYear", value=academicYear, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="academicTerm", value=academicTerm, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="depId", value=depId, cfsqltype="cf_sql_varchar" );
			
			rs_dep = queryObj.execute( sql=sql ).getResult();
		}
		
		targetArgs = structNew();
		
		currentTab = event.getArg("TabID", "labSchema");
	
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('programSchema')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">培养方案</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 course"></i>教学计划
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<cfif len(academicYear) and len(academicTerm)>
			<!--- 活动学期数据正确 --->
			<li>
				<div class="clearfix" id="summary">
					
					<div class="UItab">
						<div class="tabLables">
							<span <cfif currentTab eq "labSchema">class="active"</cfif> id="labSchema" tabTarget="Schema">概况</span>
							<span <cfif currentTab eq "labDetail">class="active"</cfif> id="labDetail" tabTarget="Detail">学期教学计划明细</span>
						</div>
					</div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
						
							/* init Tab */
							$("div.tabContent[@id!=' + $targetID + ']").hide();
							$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
							$("div.tabLables > span").click(function(){
								var $targetID = $(this).attr("tabTarget");
							
								$("div.tabLables span").removeClass("active");
								$(this).addClass("active");
							
								$("div.tabContent[@id!=' + $targetID + ']").hide();
								$("div.tabContent#" + $targetID).show();
							});
						
						});
						// -->
						//]]>
					</script>
					
					<div id="Schema" class="tabContent">

						<div class="noticeBlock">
							<h3><cfoutput>#academicYear#-#academicTerm#</cfoutput>学期</h3>
							<p><span class="img icon16x16 message"></span>根据培养方案, 当前学期各任课单位所需承担的教学任务工作量分布如下.</p>
							<hr/>
						</div>

						<div id="summaryChart" style="width:auto; height:<cfoutput>#(rs_plan.recordCount * 50)#</cfoutput>px;"></div>
					
							<cfset xAxis_categories = "" />
				
                        	<cfloop query="rs_plan">
								<cfset xAxis_categories = listAppend(xAxis_categories, "'" & rs_plan.institute_short & "'") />
							</cfloop>
					
							<cfset series_date1 = "" />
						
                        	<cfloop query="rs_plan">
								<cfset series_date1 = listAppend(series_date1, rs_plan.prop_id1) />
							</cfloop>
					
							<cfset series_date2 = "" />
					
                    		<cfloop query="rs_plan">
								<cfset series_date2 = listAppend(series_date2, rs_plan.prop_id2) />
							</cfloop>
					
					
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								var chart;
							
								$(document).ready(function() {
								
									chart = new Highcharts.Chart({
										chart: {
											renderTo: 'summaryChart',
											type: 'bar'
										},
										title: {
											text: '培养方案专业授课计划状态统计'
										},
										subtitle: {
											text: '<cfoutput>#academicYear#学年#dictAdvice.getTerm(academicTerm)#</cfoutput>'
										},
										xAxis: {
											categories: [<cfoutput>#xAxis_categories#</cfoutput>],
											title: {
												text: null
											},
											labels: {
												style: {
													fontSize: '12px'
												}
											}
										},
										yAxis: {
											min: 0,
											title: {
												text: '专业授课计划门次',
												align: 'high'
											}
										},
										tooltip: {
											formatter: function() {
												return ''+
													this.series.name +': '+ this.y +' 门次';
												}
										},
										legend: {
											layout: 'vertical',
											align: 'right',
											verticalAlign: 'top',
											x: 0,
											y: 100,
											floating: false,
											borderWidth: 1,
											backgroundColor: '#FFFFFF',
											shadow: true
										},
										credits: {
											enabled: false
										},
										series: [
											{
												name: '必修',
												data: [<cfoutput>#series_date1#</cfoutput>]
											},
											{
												name: '限选',
												data: [<cfoutput>#series_date2#</cfoutput>]
											}
										]
									});
							
								});
								// -->
								//]]>
							</script>
						</div>
					
					<div id="Detail" class="tabContent">
						
                		<cfloop query="rs_dep" >
							
							<cfset structInsert(targetArgs, "DepID", rs_dep.institute_id, true) />
							
							<div class="noticeBlock">
								<h3><cfoutput>#rs_dep.institute_name#</cfoutput></h3>
								<p><span class="img icon16x16 message"></span>点击专业名称查看该专业教学计划详细内容, 或<a href="<cfoutput>#buildURL('institutePlanDownloadExcel', targetArgs)#</cfoutput>">下载学院学期教学计划</a>.</p>
								<hr/>
							</div>
							
                              <cfset sql = "SELECT 
												t_subject.sbj_id, t_subject.sbj_name,
                                  			    t_subject.term_start, t_subject.level_code
											FROM t_schema a
									   		     INNER JOIN t_subject ON t_subject.sbj_id = a.sbj_id 
						 						 INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id   
											WHERE 
												a.academic_year = :academicYear 
												AND 
												a.academic_term = :academicTerm 
												AND 
												t_institute.institute_id = :depID 
												AND 
												t_subject.sbj_direction = '0'
											GROUP BY 
												t_subject.sbj_id, t_subject.sbj_name, t_subject.term_start, t_subject.level_code
											ORDER BY 
												t_subject.sbj_name"/>
                                                
                              <cfset queryObj = new Query( datasource=application.dnsSlave ) />
							  <cfset queryObj.addParam( name="academicYear", value=academicYear, cfsqltype="cf_sql_char" )/>
                              <cfset queryObj.addParam( name="academicTerm", value=academicTerm, cfsqltype="cf_sql_char" )/>
                              <cfset queryObj.addParam( name="depId", value=depId, cfsqltype="cf_sql_varchar" )/>
                              
                              <cfset rs_subject = queryObj.execute( sql=sql ).getResult()/>
							
							<div class="clearfix">
								<div class="UICardTable">
                                	<cfloop query="rs_subject" >
										<cfset structInsert(targetArgs, "SubID", rs_subject.sbj_id, true) />
										<dl>
											<dt>
												<a href="<cfoutput>#buildURL('planSchemaBySubject', targetArgs)#</cfoutput>">
													<em class="subject"><!--imgholder--></em>
													<dd>
														<h3><cfoutput>#rs_subject.sbj_name#</cfoutput></h3>
														<div><cfoutput>#dictAdvice.getTermEnrol(rs_subject.term_start)#-#dictAdvice.getStudentLevel(rs_subject.level_code)#</cfoutput></div>
													</dd>
												</a>
											</dt>
										</dl>
									</cfloop>
								</div>
							</div>
							
						</cfloop>
						
					</div>
					
					
				</div>
			</li>
			<cfelse>
			<!--- 要求设置一个数据处理学期 --->
			<li>
				<div class="clearfix" id="termSelector">
                    <cfset sql = " SELECT 
										a.term_id, a.academic_year, a.academic_term
									FROM t_term a 
									WHERE SUBSTR(a.academic_year,1,4) > :yearStart 
										  AND 
										  SUBSTR(a.academic_year,1,4) < :yearEnd 
									ORDER BY a.term_id"/>
                                    
					<cfset queryObj = new Query( datasource=application.dnsSlave ) />
					<cfset queryObj.addParam( name="yearStart", value=(year(now())-2), cfsqltype="cf_sql_char" )/>
                    <cfset queryObj.addParam( name="yearEnd", value=(year(now())+1), cfsqltype="cf_sql_char" )/>
                    
                    <cfset rs_term= queryObj.execute( sql=sql ).getResult()/>
					<div class="noticeBlock">
						<p><span class="img icon16x16 message"></span>请指定当前教学计划的学期</p>
						<ol>
                            <cfloop query="rs_term" >
								<li class="friendly"><span class="img icon10x10 execute"></span><a rowid="<cfoutput>#rs_term.term_id#</cfoutput>" href="javascript:void(0);"><cfoutput>#rs_term.academic_year#</cfoutput>-<cfoutput>#dictAdvice.getTermName(rs_term.academic_term)#</cfoutput></a></li>
							</cfloop>
						</ol>
					</div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							
							$("a[rowid]").click(function(){
							
								var rowid = $(this).attr("rowid");
							
								$.post(
										"<cfoutput>#buildURL('apiTermPropChange')#</cfoutput>", 
										{
											'tid' : rowid,
											'prop' : "ForCourse",
											'status' : true,
											'seed': (new Date()).getTime()
										}, 
										function(data) {
										
											result = $.parseJSON(data);
										
											if (result.ForCourse) {
												window.location.reload(true);
											}
										
										});
							});
							
						});
						// -->
						//]]>
					</script>
					
				</div>
			</li>
		</cfif>		
	</ul>
</div>

